package com.example.hospital.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hospital.dto.RefundQuery;
import com.example.hospital.entity.Refund;
import com.example.hospital.service.RefundService;
import com.example.hospital.mapper.RefundMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Oreki
 * @description 针对表【refund】的数据库操作Service实现
 * @createDate 2024-12-27 16:53:20
 */
@Service
public class RefundServiceImpl extends ServiceImpl<RefundMapper, Refund>
        implements RefundService {

    @Override
    public List<Refund> listRefunds(RefundQuery refundQuery) {
        if (refundQuery == null) {
            return list();
        }
        Integer paymentId = refundQuery.getPaymentId();
        Integer refundAmount = refundQuery.getRefundAmount();
        String refundReason = refundQuery.getRefundReason();
        String startTime = refundQuery.getStartTime();
        String endTime = refundQuery.getEndTime();
        return lambdaQuery()
                .eq(paymentId != null, Refund::getPaymentId, paymentId)
                .eq(refundAmount != null, Refund::getRefundAmount, refundAmount)
                .like(StrUtil.isNotEmpty(refundReason), Refund::getRefundReason, refundReason)
                .ge(StrUtil.isNotEmpty(startTime), Refund::getRefundTime, startTime)
                .le(StrUtil.isNotEmpty(endTime), Refund::getRefundTime, endTime)
                .list();
    }
}




